﻿using System.Linq;
using System.Text;
//using ViennaAdvantage.Process;
using VAdvantage.Classes;
//using ViennaAdvantage.Model;
using VAdvantage.DataBase;
using VAdvantage.SqlExec;
using System.Data;
using System.Data.SqlClient;
using VAdvantage.Logging;
using VAdvantage.Utility;
using VAdvantage.Report;
//using VAdvantage.Controller;
using VAdvantage.Model;
using VAdvantage.Grids;
using System;

namespace VAdvantage.Model
{
    public class CalloutDate : CalloutEngine
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="WindowNo"></param>
        /// <param name="mTab"></param>
        /// <param name="mField"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public String ToDate(Ctx ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
        {
            if (value == DBNull.Value || value == null || value.ToString() == "")
            {
                return "";
            }
            if (IsCalloutActive())
            {
                return "";
            }
            try
            {
                SetCalloutActive(true);
                if (Util.GetValueOfDateTime(value) < Util.GetValueOfDateTime(mTab.GetValue("FromDate")))
                {
                    ShowMessage.Info("ToDateShouldBeGreaterThanFromDate", true, null, null);
                    mTab.SetValue("ToDate", Util.GetValueOfDateTime(mTab.GetValue("FromDate")));
                }
                SetCalloutActive(false);
            }
            catch
            {

            }
            return "";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="WindowNo"></param>
        /// <param name="mTab"></param>
        /// <param name="mField"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public String TimeRecordDate(Ctx ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
        {
            if (value == DBNull.Value || value == null || value.ToString() == "")
            {
                return "";
            }
            try
            {
                int S_TimeExpense_ID = Util.GetValueOfInt(mTab.GetValue("S_TimeExpense_ID"));
                X_S_TimeExpense te = new X_S_TimeExpense(Envs.GetCtx(), S_TimeExpense_ID, null);
                //X_C_ResourcePeriod rp = new X_C_ResourcePeriod(Envs.GetCtx(), S_TimeExpense_ID, null);
                DateTime? fromDate = Util.GetValueOfDateTime(te.GetFROMDATE());
                DateTime? toDate = Util.GetValueOfDateTime(te.GetToDate());
                if (Util.GetValueOfDateTime(value) >= fromDate && Util.GetValueOfDateTime(value) <= toDate)
                {

                }
                else
                {
                    ShowMessage.Info("DateMustBeBetweenFromAndToDateAtHeader", true, null, null);
                    mTab.SetValue("DateExpense", null);
                }
            }
            catch
            {

            }
            return "";
        }
    }
}
